package p.ithorns.integration.transform.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import p.ithorns.integration.transform.entity.Account;
import p.ithorns.integration.transform.mapper.AccountMapper;

import java.util.List;

/**
 * Description:
 * <p>AccountService</p>
 * @author Created By Ht_L. 2019/4/22-19:04
 */
@Slf4j
@Service
public class AccountService {

    @Autowired
    private AccountMapper mapper;

    public void onMessage(String message){  //ex

    }

    public void deduct(Integer userId, int money)  {
        QueryWrapper<Account> query = new QueryWrapper<>();
        query.eq("user_id", userId);
        List<Account> list = mapper.selectList(query);

        // 未知账户
        if (CollectionUtils.isEmpty(list)) {
            throw new  RuntimeException("账户扣款失败：未知的用户或账户");
        }
    }
}
